<template>
	<div>
		<el-form ref="roleForm" :model="form" :rules="rules"  label-width="80px">

			<el-form-item label="角色名称" prop="roleName">
				<el-input v-model="form.roleName"></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'RoleEdit',
		components: {

		},
		props: [
			'showEdit',
			'roleId'
		],
		data() {
			return {
				form: {
					roleId: '',
					roleName: '',
					active: null,
				},
				rules:{
					
					//
					roleName:[
						//规则1 
						{required:true,message: '角色名称必填',trigger:'blur'}
					]
				}
			}
		},
		methods: {
			save() {

				//在提交之前，验证表单是否通过验证
				this.$refs.roleForm.validate((validate,unValidFiled)=>{
					if(validate){
						this.axios.get('/role?type=save', (data) => {
							if (data) {
								this.$emit('update:showEdit', false)
								this.$emit('update')
							}
						}, this.form, '保存成功');
					}
				})

				



			}
		},
		created() {

			if (this.roleId) {
				//当修改的时候 需要根据用户的 id， 将数据查询到页面
				this.axios.get('/role?type=toEdit', (data) => {
					console.log(data)
					this.form = data;
				}, {
					roleId: this.roleId
				});

			}

		}
	}
</script>

<style>
</style>
